﻿
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using Utils;
using PanasonicWarranty.DAL;
namespace PanasonicWarranty.Business
{
    public partial class SmsMtReport
    {
    	#region public properties
		[Required(ErrorMessage="MtGuid Required")]
		public Guid MtGuid { get; set; }
		public DateTime? SentTime { get; set; }
		public string Status { get; set; }
		public DateTime? ReportTime { get; set; }
		public string ReportStatus { get; set; }
		#endregion

		#region constructor
		public SmsMtReport(){ }

		public SmsMtReport(IDataReader rd)
		{
			this.MtGuid = (Guid)rd["MtGuid"];
			this.SentTime = rd["SentTime"].Equals(DBNull.Value) ? (DateTime?)null : (DateTime)rd["SentTime"];
			this.Status = rd["Status"].ToString();
			this.ReportTime = rd["ReportTime"].Equals(DBNull.Value) ? (DateTime?)null : (DateTime)rd["ReportTime"];
			this.ReportStatus = rd["ReportStatus"].ToString();
		}
		#endregion

		#region private method
        private bool Create()
        {
            return DBSmsMtReport.Create(MtGuid, SentTime, Status, ReportTime, ReportStatus);
        }

        private bool Update()
        {
            return DBSmsMtReport.Update(MtGuid, SentTime, Status, ReportTime, ReportStatus);
        }
		#endregion

		#region public method
		public bool Save()
		{
            if(MtGuid != Guid.NewGuid())
            {
                return Update();
            }
            else
            {
                return Create();
            }
		}
		#endregion

		#region static method
        public static bool Delete(Guid MtGuid)
        {
            return DBSmsMtReport.Delete(MtGuid);
        }

        public static List<SmsMtReport> GetAll()
        {
            return ObjectClass.CreateList<SmsMtReport>(DBSmsMtReport.GetAll());
        }

        public static SmsMtReport GetByKey(Guid MtGuid)
        {
            return ObjectClass.CreateInstance<SmsMtReport>(DBSmsMtReport.GetByKey(MtGuid));
        }

        public static List<SmsMtReport> GetByTop(string top, string where, string order)
        {
            return ObjectClass.CreateList<SmsMtReport>(DBSmsMtReport.GetByTop(top, where, order));
        }
		#endregion
	}
}
